package com.niit.bigdata.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;

@Service
public class KafkaProducerService {

    private final KafkaTemplate<String, String> kafkaTemplate;

    @Autowired
    public KafkaProducerService(KafkaTemplate<String, String> kafkaTemplate) {
        this.kafkaTemplate = kafkaTemplate;
    }


    public void sendMessage(String TOPIC_NAME, String key, String data) throws Exception {
        long timestamp = System.currentTimeMillis();
        kafkaTemplate.send(TOPIC_NAME, null, timestamp, key, data);
    }

    public void sendTask(String data) throws Exception {
        long timestamp = System.currentTimeMillis();
        kafkaTemplate.send("task", null, timestamp, "task", data);
    }
}

